const uniID = require('uni-id-common')



// iss-wallpaper.obj.js
const ApiResponse = require('./common/api-response.js')
const WallpaperClassifyService = require('./service/wallpaper-classify.service')
const WallpaperImageService = require('./service/wallpaper-image.service')
const WallpaperDictService = require('./service/wallpaper-dict.service')
const WallpaperSwiperService = require('./service/wallpaper-swiper.service')


// 创建服务实例
let service_classify = null
let service_image = null
let service_dict = null
let service_swiper = null

module.exports = {
  _before() {
      const clientInfo = this.getClientInfo()
      this.clientInfo = clientInfo
      this.uniID = uniID.createInstance({clientInfo})
      this.uniIdToken = this.getUniIdToken()

      // 将当前对象(this)传递给服务实例，这样服务实例就能访问所有公共方法
      service_classify = new WallpaperClassifyService({cloudObject: this})
      service_image = new WallpaperImageService({cloudObject: this})
      service_dict = new WallpaperDictService({cloudObject: this})
	  service_swiper = new WallpaperSwiperService({cloudObject: this})
    },
	
  
  /**
   * 删除图片
   * @param {string} id - 图片云id
   * @returns {ApiResponse} 统一响应格式
   */
  async deleteImage(id) {
  	 return await service_image.deleteImage(id)
  },

  /**
   * 分页查询分类列表
   * @param {Object} query - 查询参数
   * @returns {ApiResponse} 统一响应格式
   */
  async getList_classify(query = {}) {
    return service_classify.getList(query)
  },

  /**
   * 根据id获得对应壁纸分类
   * @param {string} id - 分类ID
   * @returns {ApiResponse} 统一响应格式
   */
  async doc_classify(id) {
    return service_classify.doc(id)
  },
  
  /**
   * 新增分类（带名称唯一性校验）
   * @param {Object} data - 分类数据
   * @returns {ApiResponse} 统一响应格式
   */
  async add_classify(data) {
    return service_classify.add(data)
  },

  /**
   * 批量删除分类
   * @param {Array<string>} ids - 要删除的ID数组
   * @returns {ApiResponse} 统一响应格式
   */
  async remove_classify(ids) {
    return service_classify.remove(ids)
  },

  /**
   * 更新分类信息（带名称唯一性校验）
   * @param {Object} data - 包含id和更新数据
   * @returns {ApiResponse} 统一响应格式
   */
  async update_classify(data = {}) {
    return service_classify.update(data)
  },
  
  /**
   * 切换bool类型字段状态
   * @param {string} id - 分类ID
   * @param {string} fieldName - 字段名
   * @returns {ApiResponse} 统一响应格式
   */
  async columnToggle_classify(id, fieldName) {
    return service_classify.columnToggle(id, fieldName)
  },
  
  /**
   * 分类名称唯一性校验
   * @param {Object} data - 分类数据
   * @returns {ApiResponse} 统一响应格式
   */
  async checkNameUnique_classify(data) {
	  return service_classify.checkNameUnique(data)
  },
  
  
  
	// 壁纸图片相关方法
	async getList_image(query = {}) {
	  return service_image.getList(query)
	},
	async doc_image(id) {
	  return service_image.doc(id)
	},
	async add_image(data) {
	  return service_image.add(data)
	},
	async remove_image(ids) {
	  return service_image.remove(ids)
	},
	async update_image(data = {}) {
	  return service_image.update(data)
	},
	async columnToggle_image(id, fieldName) {
	  return service_image.columnToggle(id, fieldName)
	},
	async getClassifyOptions() {
	  return service_image.getClassifyOptions()
	},
	
	// 数据字典相关方法
	  async getList_dict(query = {}) {
	    return service_dict.getList(query)
	  },
	  
	  async doc_dict(id) {
	    return service_dict.doc(id)
	  },
	  
	  async add_dict(data) {
	    return service_dict.add(data)
	  },
	  
	  async update_dict(data = {}) {
	    return service_dict.update(data)
	  },
	  
	  async remove_dict(ids) {
	    return service_dict.remove(ids)
	  },
	  
	  async toggleStatus_dict(id) {
	    return service_dict.toggleStatus(id)
	  },
	  
	  async getOptionsByType(type, onlyEnabled = true) {
	    return service_dict.getOptionsByType(type, onlyEnabled)
	  },
	  
	  async addOption_dict(id, option) {
	    return service_dict.addOption(id, option)
	  },
	  
	  async updateOption_dict(id, code, option) {
	    return service_dict.updateOption(id, code, option)
	  },
	  
	  async removeOption_dict(id, code) {
	    return service_dict.removeOption(id, code)
	  },
	  
	  async toggleOptionStatus_dict(id, code) {
	    return service_dict.toggleOptionStatus(id, code)
	  },
	  
	  // 轮播图相关
	  // 壁纸图片相关方法
	  async getList_swiper(query = {}) {
	    return service_swiper.getList(query)
	  },
	  async doc_swiper(id) {
	    return service_swiper.doc(id)
	  },
	  async add_swiper(data) {
	    return service_swiper.add(data)
	  },
	  async remove_swiper(ids) {
	    return service_swiper.remove(ids)
	  },
	  async update_swiper(data = {}) {
	    return service_swiper.update(data)
	  },
	  async columnToggle_swiper(id, fieldName) {
	    return service_swiper.columnToggle(id, fieldName)
	  },
	  async getTypeOptions_swiper(type) {
	    return service_swiper.getTypeOptions(type)
	  }
}